//
//  SliderView.m
//  UI5_UIControl课后作业
//
//  Created by dllo on 15/11/12.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SliderView.h"

@interface SliderView ()

@property (nonatomic, assign) CGFloat red;
@property (nonatomic, assign) CGFloat green;
@property (nonatomic, assign) CGFloat blue;

@end

@implementation SliderView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.backgroundColor = [UIColor lightGrayColor];
    
    UISlider *redS = [[UISlider alloc] initWithFrame:CGRectMake(50, 100, 300, 30)];
    redS.minimumTrackTintColor = [UIColor blackColor];
    redS.maximumTrackTintColor = [UIColor whiteColor];
    [redS addTarget:self action:@selector(redS:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:redS];
    [redS release];

    UISlider *greenS = [[UISlider alloc] initWithFrame:CGRectMake(50, 300, 300, 30)];
    greenS.minimumTrackTintColor = [UIColor blackColor];
    greenS.maximumTrackTintColor = [UIColor whiteColor];
    [greenS addTarget:self action:@selector(greenS:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:greenS];
    [greenS release];
    
    UISlider *blueS = [[UISlider alloc] initWithFrame:CGRectMake(50, 500, 300, 30)];
    blueS.minimumTrackTintColor = [UIColor blackColor];
    blueS.maximumTrackTintColor = [UIColor whiteColor];
    [blueS addTarget:self action:@selector(blueS:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:blueS];
    [blueS release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(300, 30, 50, 50);
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(returnButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    
    

}

- (void)returnButton:(UIButton *)sender
{
    [self removeFromSuperview];
//    self.hidden = YES;
}

- (void)redS:(UISlider *)sender
{
    self.red = sender.value;
    NSLog(@"%f",sender.value);
        self.backgroundColor = [UIColor colorWithRed:self.red  green:self.green  blue:self.blue  alpha:1.0];
}

- (void)greenS:(UISlider *)sender
{
    self.green = sender.value;
    NSLog(@"%f",sender.value);
        self.backgroundColor = [UIColor colorWithRed:self.red  green:self.green  blue:self.blue  alpha:1.0];
}

- (void)blueS:(UISlider *)sender
{
    self.blue = sender.value;
    NSLog(@"%f",sender.value);
        self.backgroundColor = [UIColor colorWithRed:self.red  green:self.green  blue:self.blue  alpha:1.0];
}











@end
